<blockquote>
    <p>定义AOP Interceptor</p>
    <footer>
        <p>@Aop注解, 可以作用于类和方法</p>
        <p><code>Class<? extends Interceptor>[] value</code>: 指定多个拦截器</p>
        <p>@Uop注解, 可以作用于类和方法</p>
        <p><code>Class<? extends Interceptor>[] value</code>: 指定多个拦截器, 进行取消拦截</p>
    </footer>
</blockquote>
<blockquote>
    <p>示例 <code>TestInterceptor.java</code></p>
</blockquote>
<pre class="code brush:java">
package cn.jants.demos.Interceptor;

import cn.jants.common.bean.Invocation;
import cn.jants.core.ext.Interceptor;

import java.lang.reflect.InvocationTargetException;

/**
 * @author MrShun
 * @version 1.0
 */
public class TestInterceptor implements Interceptor {

    private String name;

    public TestInterceptor(){}

    public TestInterceptor(String name){
        this.name = name;
    }

    @Override
    public Object intercept(Invocation invo) throws InvocationTargetException, IllegalAccessException {
        System.out.println("这是一个自定义拦截器, 可以基于类和方法...");
        System.out.println("方法执行之前...");
        Object result = null;
        try {
            result = invo.invoke();
            System.out.println("方法执行之后...");
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            System.out.println("执行出现异常...");
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            System.out.println("执行出现异常...");
        }
        return result;
    }
}

</pre>
<blockquote>
    <p>示例 请求拦截</p>
    <footer style="color:red;">默认实例化化无参构造</footer>
</blockquote>
<pre class="code brush:java">
package cn.jants.demos;


import cn.jants.common.annotation.action.Controller;
import cn.jants.common.annotation.action.GET;
import cn.jants.common.annotation.boot.PropertyConfiguration;
import cn.jants.common.annotation.service.Aop;
import cn.jants.common.annotation.service.Application;
import cn.jants.core.startup.JTomcat;
import cn.jants.demos.Interceptor.TestInterceptor;


/**
 * Tomcat 方式启动
 *
 * @author MrShun
 * @version 1.0
 * @Date 2017/12/20
 */
@Application
@PropertyConfiguration
@Controller
public class DemosApplication {

    @GET("/aop/test")
    @Aop(TestInterceptor.class)
    public void test() {
        System.out.println("测试Aop Interceptor拦截器...");
    }


    public static void main(String[] args) {
        JTomcat.run(DemosApplication.class, 80, "/demo");
    }
}
</pre>
<blockquote>
    <p>示例 请求拦截</p>
    <footer style="color:red;">实例化有参构造</footer>
    <footer style="color:red;">必须继承AppConfiguration对象覆盖父类方法</footer>
</blockquote>
<pre class="code brush:java">
package cn.jants.demos;


import cn.jants.common.annotation.action.Controller;
import cn.jants.common.annotation.action.GET;
import cn.jants.common.annotation.boot.PropertyConfiguration;
import cn.jants.common.annotation.plugin.EnableActiveMQPlugin;
import cn.jants.common.annotation.service.Aop;
import cn.jants.common.annotation.service.Application;
import cn.jants.common.annotation.service.Autowired;
import cn.jants.core.context.AppConfiguration;
import cn.jants.core.module.HandlerManager;
import cn.jants.core.module.InterceptorManager;
import cn.jants.core.startup.JTomcat;
import cn.jants.demos.Interceptor.TestInterceptor;
import cn.jants.plugin.jms.ActiveMqTpl;


/**
 * Tomcat 方式启动
 *
 * @author MrShun
 * @version 1.0
 * @Date 2017/12/20
 */
@Application
@PropertyConfiguration
@Controller
public class DemosApplication extends AppConfiguration{


    @GET("/aop/test")
    @Aop(TestInterceptor.class)
    public void test(){
        System.out.println("测试Aop Interceptor拦截器...");
    }

    @Override
    public void configInterceptor(InterceptorManager interceptors) {
        //添加有参构造的拦截
        interceptors.add(new TestInterceptor("参数构造"));
    }

    public static void main(String[] args) {
        JTomcat.run(DemosApplication.class, 80, "/demo");
    }
}

</pre>
<blockquote>
    <p>示例 全局拦截</p>
    <footer style="color:red;">实例化有参构造</footer>
    <footer style="color:red;">必须继承AppConfiguration对象覆盖父类方法</footer>
</blockquote>
<pre class="code brush:java">
package cn.jants.demos;


import cn.jants.common.annotation.action.Controller;
import cn.jants.common.annotation.action.GET;
import cn.jants.common.annotation.boot.PropertyConfiguration;
import cn.jants.common.annotation.plugin.EnableActiveMQPlugin;
import cn.jants.common.annotation.service.Aop;
import cn.jants.common.annotation.service.Application;
import cn.jants.common.annotation.service.Autowired;
import cn.jants.core.context.AppConfiguration;
import cn.jants.core.module.HandlerManager;
import cn.jants.core.module.InterceptorManager;
import cn.jants.core.startup.JTomcat;
import cn.jants.demos.Interceptor.TestInterceptor;
import cn.jants.plugin.jms.ActiveMqTpl;


/**
 * Tomcat 方式启动
 *
 * @author MrShun
 * @version 1.0
 * @Date 2017/12/20
 */
@Application
@PropertyConfiguration
@Controller
public class DemosApplication extends AppConfiguration{


    @GET("/aop/test")
    @Aop(TestInterceptor.class)
    public void test(){
        System.out.println("测试Aop Interceptor拦截器...");
    }

    @Override
    public void configInterceptor(InterceptorManager interceptors) {
        //添加有参构造的拦截
        interceptors.add(new TestInterceptor("参数构造"));
        /**
         * 参数一： 指定拦截器
         * 参数二： 对指定包名拦截
         * 参数三： 对指定方法拦截
         */
        interceptors.addGlobal(new TestInterceptor("参数构造"), "cn.jants.demos", "find");
    }

    public static void main(String[] args) {
        JTomcat.run(DemosApplication.class, 80, "/demo");
    }
}

</pre>
<script type="text/javascript">
    $(function () {
        SyntaxHighlighter.highlight();
        $(".toolbar").remove();
    });
</script>